const { T_exam_question } = require('../models/t_exam_question');
const { sequelize } = require('../utill/getSequelize');

exports.getQuestionType = async (req, res) => {
    try {
        const subId = req.query.subId;

        // 使用 await 等待查询结果
        const questionTypes = await T_exam_question.findAll({
            where: {
                sub_id: subId
            },
            attributes: [
                [sequelize.literal('DISTINCT `type`'), 'type']
            ],
        });

        console.log(questionTypes);

        res.json({
            "code": 200,
            "content": questionTypes
        });
    } catch (error) {
        console.error('Failed to fetch question types:', error);
        res.json({
            "code": 500,
            "content": error.message // 修改为 error.message
        });
    }
}